package resoft.jeasyform.event;

import charva.awt.event.ActionListener;
import charva.awt.event.ActionEvent;
import resoft.jeasyform.components.Window;
import resoft.jeasyform.components.Component;

import java.util.Collection;
import java.util.Iterator;

/**
 * <p></p>
 * User: albert
 * Date: Aug 27, 2007
 * Time: 12:39:28 AM
 */
public class InputFieldEnterPressedEventAdapter implements ActionListener {
    public InputFieldEnterPressedEventAdapter(Window parentWindow, Component filed, Collection postEventChain) {
        this.parentWindow = parentWindow;
        this.field = filed;
        this.postEventChain = postEventChain;
    }

    public void actionPerformed(ActionEvent actionEvent) {
        for(Iterator itr = postEventChain.iterator();itr.hasNext();) {
            EventHandler event = (EventHandler) itr.next();
            if(!event.execute(parentWindow,field,EventType.TextFieldPostEvent)) {
                return;
            }
        }
        parentWindow.changeFocus(field);
    }

    private Window parentWindow;
    private Component field;
    private Collection postEventChain;
}
